package genosAgape.ui.menuPrincipal;

import genosAgape.ui.MdiGA;
import genosAgape.ui.reports.Relatorio;
import genosAgape.ui.usuario.Pesquisar;
import genosAgape.ui.usuario.Cadastrar;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

public class Adm extends JPanel {
	
	private JButton btnUsuarios;
	private JButton btnRelatorios;	
	private JButton btnEditar;
	
	public Adm() {
		
		setLayout(null);
		setOpaque(false);
		
		JPanel painel = new JPanel();
		painel.setOpaque(false);
		painel.setBounds(5, 5, 311, 282);
		painel.setBorder(null);
		painel.setLayout(null);
		painel.setBackground(Color.WHITE);
		add(painel);
		
		btnUsuarios = new JButton("Cadastrar Usuario");
		btnRelatorios = new JButton("Relatorios");		
		
		btnUsuarios.setBounds(156, 11, 137, 122);
		btnUsuarios.setIcon(new ImageIcon(Adm.class.getResource("/genosAgape/ui/img/icons/users.png")));
		
		btnRelatorios.setIcon(new ImageIcon(Adm.class.getResource("/genosAgape/ui/img/icons/report.png")));
		btnRelatorios.setBounds(9, 11, 137, 122);
		
		painel.add(btnUsuarios);
		painel.add(btnRelatorios);
		
		btnEditar = new JButton("Editar Usuario");
		btnEditar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					Pesquisar pt = Pesquisar.getInstance();
					if(pt.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(pt);
					pt.setSelected(true);
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnEditar.setBounds(156, 144, 137, 122);
		painel.add(btnEditar);
		
		addListener();
	}
	
	
	
	private void addListener(){
		btnUsuarios.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Cadastrar pt = Cadastrar.getInstance();
					if(pt.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(pt);
					pt.setSelected(true);
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		
		btnRelatorios.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Relatorio rl = Relatorio.getInstance();
					if(rl.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(rl);
					rl.setSelected(true);
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
			}
		});		
	}
}
